/* 全局消息通告 */
// announcementService.js

const announcementService = {
  announcements: [],
  addAnnouncement(announcement) {
    this.announcements.push(announcement);
  },
  removeAnnouncement(announcement) {
    const index = this.announcements.indexOf(announcement);
    if (index !== -1) {
      this.announcements.splice(index, 1);
    }
  },
  initWebSocket() {
    // 建立WebSocket连接
    const socket = new WebSocket('ws://your-backend-server');

    // 监听后端发送的公告消息
    socket.onmessage = function (event) {
      const message = event.data;
      // 处理后端发送的公告消息
      announcementService.addAnnouncement(message);
    };
  }
};

export default announcementService;
